<?php
//Set page title
if( isset($s_pageTitle) && $s_pageTitle !== "" ) {
    $this->pageTitle = Yii::app()->name." - ".$s_pageTitle;
}


/** Create paging for array of Items ************************************************
 * @author	RoamCat
 *
 * @param	$i_totalItem: length to create string
 * @param	$i_amountPerPage:
 * @param	$i_currentPage: get current page of Items
 * ************************************************************************
 */
function CreatHomePaging ($i_totalItem, $i_amountPerPage, $i_currentPage)
{
    //Init
    $i_totalPage = 0;

    //Calculate amount of page
    if($i_totalItem % $i_amountPerPage == 0)
        $i_totalPage = $i_totalItem / $i_amountPerPage;
    else
        $i_totalPage = (int) ($i_totalItem / $i_amountPerPage) + 1;


    echo "<div class='box_paging'>";
    echo "<a href='./page-1.html'>◄</a> ";

    $iBatDau	= 1;
    $iketthuc	= $i_totalPage;

    if (($i_currentPage - 4)>1) $iBatDau = $i_currentPage - 4;

    if(($i_currentPage + 4) < $i_totalPage) $iketthuc = $i_currentPage + 4;

    if(($iBatDau -1) >= 1) echo ".... ";

    for ($i = $iBatDau; $i <= $iketthuc; $i++)
    {
        if($i==$i_currentPage)
            echo "<a href='javascript:void(0);' class='selected_page'>".$i."</a> ";
        else
            echo "<a href='./page-".$i.".html'>".$i."</a> ";
    }//End for

    if(($iketthuc +1) <= $i_totalPage)
        echo " ....";

    echo "<a href='./page-".$i_totalPage.".html'>►</a>";
    echo "</div>";
}


echo $this->renderPartial("leftnav", array("arr_category"=>$arr_category));
?>

<div class="grid_712">
        <div class="box">
            <h1>Danh Sách Sản Phẩm</h1>

            <?php if ( isset($s_errorMsg) && $s_errorMsg != "") {?>
            <div id="div_contentBox">
                <p class="error_message"><?=$s_errorMsg;?></p>
            </div>
            <?php } else {?>

            <div class="clear"></div>
            <?php CreatHomePaging($i_totalItem, $i_amountPerPage, $i_currentPage);?>
            <div class="clear"></div>

            <div class="galleries_item">
                <?php
                $itemp = 0;
                foreach ($arr_product as $o_product )
                {
                    if ($o_product instanceof Product )
                    {
                ?>
                    <div class = "item_vertical">
                        <a href="<?=Yii::app()->createAbsoluteUrl( "product/detail",
                                                                   array( "urlMapping" => $o_product->url_mapping, 
                                                                          "key"        => $o_product->identification
                                                                        )
                                                                 );?>">
                            <img alt = "album" src = "<?=$o_product->image;?>" />
                        </a>

                        <div class="item_content border_radius_all">
                            <a href="<?=Yii::app()->createAbsoluteUrl( "article/detail",
                                                                       array( "urlMapping" => $o_product->url_mapping, 
                                                                              "key"        => $o_product->identification
                                                                            )
                                                                     );?>">
                                <span class="item_title"><?=$o_product->subject;?></span><br/>
                            </a>

                            <div class="position_relative">
                                <span class="item_sub_title"><?=$o_product->price;?></span>
                            </div>

                            <div class="butt_icon">
                                <a 
                                    title    = "Đăng lên ZingMe"
                                    target    = "_blank"
                                    href    = "http://link.apps.zing.vn/pro/view/conn/share?u="
                                >
                                    <span class="icon_social_network icon_zingme"></span>
                                </a>

                                <span class="icon_social_network icon_govn"></span>
                                <span class="icon_social_network icon_facebook" onclick="facebook_sharing('');"></span>

                            </div>
                        </div><!-- End item_content -->
                    </div> <!-- End item_vertical -->
                <?php
                        $itemp ++;
                        if($itemp == 4)
                        {
                            echo "<div class='clear'></div>";
                            $itemp = 0;
                        }
                    }
                } ?>
            </div><!-- End galleries_item -->

            <div class="clear"></div>
            <?php CreatHomePaging($i_totalItem, $i_amountPerPage, $i_currentPage);?>
            <div class="clear"></div>
            <?php }?>

        </div><!-- End box -->
</div><!-- End class grid_712 -->